<template>
	<view>
		<u-list @scrolltolower="scrolltolower">
			<u-list-item v-for="(item, index) in articleList" :key="index">
				<u-cell :title="item.title">
					<u-avatar slot="icon" shape="square" size="35"
						:src="'http://127.0.0.1:8080/blogimages/'+item.imgUrl" customStyle="margin: -3px 5px -3px 0">
					</u-avatar>
				</u-cell>
			</u-list-item>

		</u-list>
		<!-- <uni-fab  horizontal="right" vertical="bottom" @fabClick="toAddArticle"
			></uni-fab> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				articleList: [],
				article: {},
				pageNum:1,
				pageSize:15,
				total:0
			};
		},
		onLoad() {
			uni.startPullDownRefresh();
			// var _this = this
			// uni.$on('addArticle',function(data){
			// 	_this.getAllArticle()
			// })
			this.getAllArticle()
			// setTimeout(function() {

			// }, 3000);
		},
		onPullDownRefresh() {
			this.articleList=[]
			this.pageNum = 1
			this.getAllArticle()
		},
		// onReachBottom(){
		// 	console.log('到底了')
		// 	uni.$u.toast('到底了')
		// },
		methods: {
			// toAddArticle(){
			// 	uni.navigateTo({
			// 		url:'/pages/swiper/addArticle'
			// 	})
			// },
			scrolltolower() {
				
				
				if(this.pageNum*this.pageSize>this.total){
					uni.$u.toast('到底了')
				}else{
					this.getAllArticle()
					this.pageNum++
				}
				
				console.log(this.pageNum)
			},
			getAllArticle() {
				uni.request({
					url: 'http://127.0.0.1:8080/article/getArticlePage/'+this.pageNum+'/'+this.pageSize,
					method: 'POST',
					header: {
						'token': uni.getStorageSync('token')
					},
					data: this.article,
					success: (res) => {
						uni.stopPullDownRefresh();
						console.log(res);
						//this.articleList = res.data.data.list
						this.total = res.data.data.total
						for (let s of res.data.data.list) {
							this.articleList.push(s)
						}

					},
					fail: (err) => {
						console.log('err', err)
					}
				});
			}
		},

	}
</script>

<style lang="scss">

</style>
